package com.lovo;

import java.io.*;

public class Test04 {
    public void read(){
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("d:/1.txt");
            int d;
            byte [] bs = new byte[1024];
            while((d = fis.read(bs)) != -1){
                System.out.println(new String(bs));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void reader(){
        FileReader reader = null;
        try {
            reader = new FileReader("d:/1.txt");
            int len = 0;
            char [] cs = new char[1024];
            while((len = reader.read(cs)) != -1){
                System.out.println(new String(cs,0,len));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(reader != null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void write(){
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("d:/2.txt");
            fos.write("张三同学".getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
    public static void main(String[] args) {
       Test04 test04 = new Test04();
//       test04.read();
//       test04.write();
        test04.reader();
    }
}
